﻿using System.Text;

namespace TemplateMethod
{
    internal class StringDisplay : AbstractDisplay
    {
        private readonly string text;
        private readonly int width;

        public StringDisplay(string text)
        {
            this.text = text;
            this.width = Encoding.UTF8.GetBytes(text).Length;
        }

        public override void Close()
        {
            this.PrintLine();
        }

        public override void Open()
        {
            this.PrintLine();
        }

        public override void Print()
        {
            Console.WriteLine($"|{text}|");
        }

        private void PrintLine()
        {
            Console.Write("+");
            for (var i = 0; i < this.width; i++)
            {
                Console.Write("-");
            }
            Console.WriteLine("+");
        }
    }
}
